package com.tiancheng.trade.merchant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.commom.web.model.response.QueryMccRes;
import com.tiancheng.trade.merchant.convert.IndustryConvert;
import com.tiancheng.trade.merchant.mapper.IndustryMapper;
import com.tiancheng.trade.merchant.model.Industry;
import com.tiancheng.trade.merchant.service.IIndustryService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndustryServiceImpl extends ServiceImpl<IndustryMapper, Industry> implements IIndustryService {
    @Override
    public List<QueryMccRes> queryMcc(String mccName, String paymentChannel) {
        if(paymentChannel.equals(PaymentChannelEnum.UMS_SHOP.getCode())|| paymentChannel.equals(PaymentChannelEnum.UMS_DHJT.getCode())){
            paymentChannel=PaymentChannelEnum.UMS.getCode();
        }
        List<Industry> list = this.list(new LambdaQueryWrapper<Industry>().eq(Industry::getPaymentChannel, paymentChannel)
                .like(StringUtils.isNotEmpty(mccName), Industry::getMccName, mccName));
        if (CollectionUtils.isNotEmpty(list)) {
            return IndustryConvert.INSTANCE.convert(list);
        }
        return null;
    }

    @Override
    public List<QueryMccRes> queryMccByCode(String mccCode, String paymentChannel) {
        List<Industry> list = this.list(new LambdaQueryWrapper<Industry>().eq(Industry::getPaymentChannel, paymentChannel)
                .like(StringUtils.isNotEmpty(mccCode), Industry::getMccCode, mccCode));
        if (CollectionUtils.isNotEmpty(list)) {
            return IndustryConvert.INSTANCE.convert(list);
        }
        return null;
    }
}
